package com.segersten.othello.service.akka.game;

import com.segersten.othello.service.akka.GameObjectPool;
import com.segersten.othello.service.akka.GameObjectReference;
import com.segersten.othello.service.akka.Player;

public class DefaultBoardActorFactory implements BoardActorFactory {
    
    GameObjectPool gameObjectPool;
    
    public DefaultBoardActorFactory(GameObjectPool gameObjectPool) {
        this.gameObjectPool = gameObjectPool;
    }

	@Override
    public String createBoard(Player player1, Player player2) {
	    GameObjectReference ref = gameObjectPool.createBoardServiceActor(boardReference(player1, player2));
		CreateBoard createBoard = new CreateBoard(8, player1, player2);
		gameObjectPool.tell(ref, createBoard);
		return gameObjectPool.getReference(ref);
	}

	private String boardReference(Player player1, Player player2) {
		String uniqueString = String.format("%s%s%s", player1, player2, System.currentTimeMillis());
		return "board:" + Integer.toString(uniqueString.hashCode());
	}

}
